﻿using System;
using AutoMapper;
using Pay.Data;
using Pay.DTO;
using Pay.TO;
using Pay.Core;
using Pay.IService;

namespace Pay.Service.AutoMapper {
	public class MerchantMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public MerchantMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
            _cfg.CreateMap<merchant_dto, Merchant>()
                .ForMember(dest => dest.MerchantNo, src => src.MapFrom(c => c.merchant_no))
                .ForMember(dest => dest.TradeOutPay, src => src.MapFrom(c => c.trade_outpay))
                .ForMember(dest => dest.IsSupplier, src => src.MapFrom(c => c.is_supplier))
                .ForMember(dest => dest.IsOEM, src => src.MapFrom(c => c.is_oem))
                .ForMember(dest => dest.IsPlatform, src => src.MapFrom(c => c.is_platform))
                .ForMember(dest => dest.OemId, src => src.MapFrom(c => c.oem_id))
                .ForMember(dest => dest.ParentId, src => src.MapFrom(c => c.parent_id))
                .ForMember(dest => dest.PublicKey, src => src.MapFrom(c => c.public_key))
                .ForMember(dest => dest.AuthStatus, src => src.MapFrom(c => c.auth_status))
                .ForMember(dest => dest.CreateTime, src => src.MapFrom(c => c.create_time.ToUnix()))
                .ForMember(dest => dest.LoginTime, src => src.MapFrom(c => c.login_time.ToUnix()))
                .ForMember(dest => dest.Setting, src => src.MapFrom(c => c.setting.ToJson()))
                .ForMember(dest => dest.MobileCode, src => src.MapFrom(c => c.mobile_code))
                .ForMember(dest => dest.Domain, src => src.MapFrom(c => c.domain))
                .ForMember(dest => dest.UpgradeTime, src => src.MapFrom(c => c.upgrade_time));
            
            _cfg.CreateMap<Merchant, merchant_dto>()
				.ForMember(dest => dest.merchant_no, src => src.MapFrom(c => c.MerchantNo))
				.ForMember(dest => dest.trade_outpay, src => src.MapFrom(c => c.TradeOutPay))
				.ForMember(dest => dest.is_supplier, src => src.MapFrom(c => c.IsSupplier))
				.ForMember(dest => dest.is_oem, src => src.MapFrom(c => c.IsOEM))
				.ForMember(dest => dest.is_platform, src => src.MapFrom(c => c.IsPlatform))
				.ForMember(dest => dest.parent_id, src => src.MapFrom(c => c.ParentId))
				.ForMember(dest => dest.public_key, src => src.MapFrom(c => c.PublicKey))
				.ForMember(dest => dest.auth_status, src => src.MapFrom(c => c.AuthStatus))
                .ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()))
				.ForMember(dest => dest.login_time, src => src.MapFrom(c => c.LoginTime.ToDateTime()))
				.ForMember(dest => dest.setting, src => src.MapFrom(c => c.Setting.ToObject<merchant_setting>()))
                .ForMember(dest => dest.oem_id, src => src.MapFrom(c => c.OemId))
                .ForMember(dest => dest.domain, src => src.MapFrom(c => c.Domain))
                .ForMember(dest => dest.upgrade_time, src => src.MapFrom(c => c.UpgradeTime));

            _cfg.CreateMap<merchant_info, Merchant>()
                .ForMember(dest => dest.MerchantNo, src => src.MapFrom(c => c.merchant_no))
                .ForMember(dest => dest.TradeOutPay, src => src.MapFrom(c => c.trade_outpay))
                .ForMember(dest => dest.IsSupplier, src => src.MapFrom(c => c.is_supplier))
                .ForMember(dest => dest.IsOEM, src => src.MapFrom(c => c.is_oem))
                .ForMember(dest => dest.IsPlatform, src => src.MapFrom(c => c.is_platform))
                .ForMember(dest => dest.OemId, src => src.MapFrom(c => c.oem_id))
                .ForMember(dest => dest.ParentId, src => src.MapFrom(c => c.parent_id))
                .ForMember(dest => dest.PublicKey, src => src.MapFrom(c => c.public_key))
                .ForMember(dest => dest.AuthStatus, src => src.MapFrom(c => c.auth_status))
                .ForMember(dest => dest.CreateTime, src => src.MapFrom(c => c.create_time.ToUnix()))
                .ForMember(dest => dest.LoginTime, src => src.MapFrom(c => c.login_time.ToUnix()))
                .ForMember(dest => dest.Setting, src => src.MapFrom(c => c.setting.ToJson()))
                .ForMember(dest => dest.Domain, src => src.MapFrom(c => c.domain));
            _cfg.CreateMap<Merchant, merchant_info>()
                .ForMember(dest => dest.merchant_no, src => src.MapFrom(c => c.MerchantNo))
                .ForMember(dest => dest.trade_outpay, src => src.MapFrom(c => c.TradeOutPay))
                .ForMember(dest => dest.is_supplier, src => src.MapFrom(c => c.IsSupplier))
                .ForMember(dest => dest.is_oem, src => src.MapFrom(c => c.IsOEM))
                .ForMember(dest => dest.is_platform, src => src.MapFrom(c => c.IsPlatform))
                .ForMember(dest => dest.parent_id, src => src.MapFrom(c => c.ParentId))
                .ForMember(dest => dest.public_key, src => src.MapFrom(c => c.PublicKey))
                .ForMember(dest => dest.auth_status, src => src.MapFrom(c => c.AuthStatus))
                .ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()))
                .ForMember(dest => dest.login_time, src => src.MapFrom(c => c.LoginTime.ToDateTime()))
                .ForMember(dest => dest.setting, src => src.MapFrom(c => c.Setting.ToObject<merchant_setting>()))
                .ForMember(dest => dest.oem_id, src => src.MapFrom(c => c.OemId))
                .ForMember(dest => dest.domain, src => src.MapFrom(c => c.Domain));

            _cfg.CreateMap<PagedResult<Merchant>, PagedResult<merchant_info>>();

			_cfg.CreateMap<verify_auth_model, auth_info_setting>()
				.ForMember(dest => dest.card_handheld, src => src.Ignore())
				.ForMember(dest => dest.card_negative, src => src.Ignore())
				.ForMember(dest => dest.card_positive, src => src.Ignore());
			_cfg.CreateMap<auth_info_setting, auth_info_result>();
			_cfg.CreateMap<verify_auth_model, batch_auth_model_item>();
			_cfg.CreateMap<batch_auth_model_item, auth_info_setting>();

		}
	}
}
